home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frm7_4_5
- Caption = "Binary Search"
- ClientHeight = 1044
- ClientLeft = 1740
- ClientTop = 2496
- ClientWidth = 3588
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 7.8
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 1044
- ScaleWidth = 3588
- Begin VB.PictureBox picResult
- Height = 255
- Left = 1440
- ScaleHeight = 204
- ScaleWidth = 2004
- TabIndex = 3
- Top = 600
- Width = 2055
- End
- Begin VB.CommandButton cmdSearch
- Caption = "Search"
- Default = -1 'True
- Height = 495
- Left = 120
- TabIndex = 2
- Top = 480
- Width = 1215
- End
- Begin VB.TextBox txtCorporation
- Height = 285
- Left = 1920
- TabIndex = 1
- Top = 120
- Width = 1575
- End
- Begin VB.Label lblName
- Alignment = 1 'Right Justify
- Caption = "Name of corporation"
- Height = 255
- Left = 0
- TabIndex = 0
- Top = 120
- Width = 1815
- End
- Attribute VB_Name = "frm7_4_5"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Dim firm(1 To 100) As String
- Dim numFirms As Integer
- Private Sub BinarySearch(corp As String, result As String)
- Dim foundFlag As Boolean
- Dim first As Integer, middle As Integer, last As Integer
- 'Array firm() assumed already ordered alphabetically
- 'Binary search of firm() for corp
- foundFlag = False
- first = 1
- last = numFirms
- Do While (first <= last) And (Not foundFlag)
- middle = Int((first + last) / 2)
- Select Case UCase(firm(middle))
- Case corp
- foundFlag = True
- Case Is > corp
- last = middle - 1
- Case Is < corp
- first = middle + 1
- End Select
- Loop
- If foundFlag Then
- result = "found"
- Else
- result = "not found"
- End If
- End Sub
- Private Sub cmdSearch_Click()
- Dim corp As String, result As String
- corp = UCase(Trim(txtCorporation.Text))
- Call BinarySearch(corp, result)
- 'Display results of search
- picResult.Cls
- picResult.Print corp; " "; result
- End Sub
- Private Sub Form_Load()
- 'Fill array with data from FIRMS.TXT
- Open App.Path & "\FIRMS.TXT" For Input As #1 'Contains up to 100 companies
- numFirms = 0
- Do While (Not EOF(1)) And (numFirms < UBound(firm))
- numFirms = numFirms + 1
- Input #1, firm(numFirms)
- Loop
- Close #1
- End Sub
-